﻿using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Xml;

namespace WeiSha.Core
{
	// Token: 0x02000028 RID: 40
	public class CopyrightView : IView
	{
		// Token: 0x0600015F RID: 351 RVA: 0x0000A20C File Offset: 0x0000840C
		public void Render(ViewContext viewContext, TextWriter writer)
		{
			HttpContextBase httpContext = viewContext.HttpContext;
			StringBuilder stringBuilder = new StringBuilder();
			try
			{
				httpContext.Response.ContentType = "text/xml";
				XmlDocument xmlDocument = this.Index(httpContext);
				StringWriter stringWriter = new StringWriter(stringBuilder);
				XmlTextWriter xmlTextWriter = null;
				try
				{
					xmlTextWriter = new XmlTextWriter(stringWriter);
					xmlTextWriter.Formatting = Formatting.Indented;
					xmlTextWriter.Indentation = 1;
					xmlTextWriter.IndentChar = '\t';
					xmlDocument.WriteTo(xmlTextWriter);
				}
				finally
				{
					bool flag = xmlTextWriter != null;
					if (flag)
					{
						xmlTextWriter.Close();
					}
				}
				writer.Write(stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				httpContext.Response.ContentType = "text/plain";
				stringBuilder.Append("Error:");
				stringBuilder.Append(ex.Message);
				writer.Write(stringBuilder.ToString());
			}
		}

		// Token: 0x06000160 RID: 352 RVA: 0x0000A2FC File Offset: 0x000084FC
		public XmlDocument Index(HttpContextBase context)
		{
			string file = Copyright.File;
			XmlDocument xmlDocument = new XmlDocument();
			bool flag = File.Exists(file);
			if (flag)
			{
				try
				{
					xmlDocument.Load(file);
				}
				catch (Exception ex)
				{
					throw ex;
				}
			}
			else
			{
				XmlNode xmlNode = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", "yes");
				xmlDocument.AppendChild(xmlNode);
				XmlElement xmlElement = xmlDocument.CreateElement("Copyright");
				xmlElement.InnerText = "版权信息可以在文件 ~/Copyright.weisha 中修改";
				xmlDocument.AppendChild(xmlElement);
			}
			return xmlDocument;
		}
	}
}
